var currentUser={};
var czxx_id=0;
var qzxx_id=0;

var msg = function(title, msg){
		Ext.Msg.show({
				title: title,
				msg: msg,
				minWidth: 300,
				modal: true,
				icon: Ext.Msg.WARNING,
				buttons: Ext.Msg.OK
		});
};

var txfw_data = [
 ['0','不提醒'],
 ['1','个人'],
 ['2','部门'],
];

var txfw_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : txfw_data
});

var pt_data = [
 ['1','高速'],
 ['2','码头'],
 ['3','门卫'],
 ['4','仓库'],
 ['5','配电房'],
 ['6','附房']
];

var pt_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : pt_data
});

var cz_data = [
	['1','出租'],
	['2','出售'],
	['3','租售']
];

var cz_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : cz_data
});

var qz_data = [
	['1','求租'],
	['2','求售'],
	['3','租售']
];

var qz_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : qz_data
});

var bz_data = [
	['1','水费'],
	['2','电费'],
	['3','租期'],
	['4','每年递增'],
	['5','电梯'],
	['6','电梯承重']
];

var bz_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : bz_data
});

var key_data = [
	['1','预约'],
	['2','有匙'],
	['3','接匙'],
	['4','直接']
];

var key_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : key_data
});

var wt_data = [
	['1','A-独家'],
	['2','B-多家'],
	['3','C-未签'],
	['4','X-限时'],
	['5','X-托管'],
	['6','X-收购']
];

var wt_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : wt_data
});

var jf_data = [
	['1','2010'],
	['2','2009'],
	['3','2008'],
	['4','2007'],
	['5','2006'],
	['6','2005'],
	['7','2004'],
	['8','2003'],
	['9','2002']
];

var jf_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : jf_data
});

var cq_data = [
	['1','不限'],
	['2','70年'],
	['3','60年'],
	['4','50年'],
	['5','40年'],
	['6','30年'],
	['7','20年'],
	['8','10年']
];

var cq_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : cq_data
});

var jg_data = [
	['1','瓦房'],
	['2','全钢'],
	['3','砖混'],
	['4','钢构']
];

var jg_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : jg_data
});

var wq_data = [
	['1','墙砖'],
	['2','瓷砖'],
	['3','涂料'],
	['4','砂浆'],
	['5','石灰']
];

var wq_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : wq_data
});

var lx_data = [
	['1','单门独院'],
	['2','单门独栋'],
	['3','分租式'],
	['4','平房'],
	['5','铁皮房'],
	['6','合租式'],
	['7','独立式']
];

var lx_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : lx_data
});

var yt_data = [
	['1','厂房'],
	['2','写字楼'],
	['3','写厂'],
	['4','铺厂'],
	['5','仓库'],
	['6','土地'],
	['7','车位'],
	['8','住宅'],
	['9','商住'],
	['10','商铺'],
	['11','其它']
];

var yt_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : yt_data
});

var cs_data = [
	['1','单层'],
	['2','双层'],
	['3','三层'],
	['4','四层'],
	['5','五层'],
	['6','六层'],
	['7','七层']
];

var cs_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : cs_data
});

var fy_data = [
	['1','商议'],
	['2','全佣'],
	['3','九折佣'],
	['4','八折佣'],
	['5','七折佣'],
	['6','六折佣'],
	['7','五折佣']
];

var fy_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : fy_data
});


var gj_data = [
	['1','中国'],
	['2','香港'],
	['3','台湾'],
	['4','海外']
];

var gj_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : gj_data
});


var gs_data = [
	['1','公盘'],
	['2','私盘']
];

var gs_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : gs_data
});


var fwwq_data = [
	['1','有围墙'],
	['2','无围墙']
];

var fwwq_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : fwwq_data
});


var xz_data = [
	['1','空置'],
	['2','居住']
];

var xz_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : xz_data
});

var zt_data = [
	['1','有效'],
	['2','预定'],
	['3','缓解'],
	['4','已租'],
	['5','已售'],
	['6','无效'],
];

var zt_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : zt_data
});

var czfs_data = [
	['1','一年一付'],
	['2','半年一付'],
	['3','一季一付'],
	['4','两月一付'],
	['5','一月一付']
];

var czfs_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : czfs_data
});

var fyfs_data = [
	['1','商议'],
	['2','全佣'],
	['3','九折佣金'],
	['4','八折佣金'],
	['5','七折佣金'],
	['6','六折佣金'],
	['7','五折佣金']
];

var fyfs_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : fyfs_data
});

var fyzj_data = [
	['1','房产证'],
	['2','小产权证']
];

var fyzj_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : fyzj_data
});

var tax_data = [
	['1','包税费'],
	['2','不包税费']
];

var tax_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : tax_data
});

var fwrs_data = [
	['50','50人'],
	['100','100人'],
	['200','200人'],
	['300','300人'],
	['400','400人'],
	['500','500人'],
	['600','600人'],
	['700','700人'],
	['800','800人'],
	['900','900人'],
	['1000','1000人'],
	['1500','1500人'],
	['2000','2000人'],
	['3000','3000人'],
];

var fwrs_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : fwrs_data
});
/*
var qy_data = [
	['1','巴城'],
	['2','城北'],
	['3','淀山湖'],
	['4','花桥'],
	['5','锦溪'],
	['6','开发区'],
	['7','陆家'],
	['8','蓬朗'],
	['9','千灯'],
	['10','石牌'],
	['11','苏州市'],
	['12','太仓市'],
	['13','吴淞江'],
	['14','玉山'],
	['15','周市'],
	['16','周庄'],
	['17','张浦']
];

var qy_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : qy_data
});
*/

var qy_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_qy'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});



var pq_data = [
	['1','城北'],
	['2','城南']
];

var pq_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : cq_data
});

var bm_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_bm'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'value'}, 
		{name:'text'}
	])
});

var yg_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_yg'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'value'}, 
		{name:'text'}
	])
});

var khxz_data = [
	['1','分租'],
	['2','合租'],
];

var khxz_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : khxz_data
});

var khyx_data = [
	['1','不急'],
	['2','很急'],
];

var khyx_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : khyx_data
});

var khqx_data = [
	['1','1个月内'],
	['2','2个月内'],
	['2','3个月内'],
];

var khqx_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : khqx_data
});

var wtly_data = [
	['1','独家'],
	['2','多家'],
	['2','网络'],
];

var wtly_store = new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : wtly_data
});


var  khxx_store = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
        url: '/desktop/get_khxx'
    }),

		reader: new Ext.data.JsonReader({
			totalProperty: 'results', 
			root: 'rows',							
			fields: [
				{name: 'id'},
				{name: 'khxm',	type: 'string'},
				{name: 'khlxr',	type: 'string'},
				{name: 'khdh',	type: 'string'},
				{name: 'khsfz',	type: 'string'},
				{name: 'khdz',	type: 'string'},
				{name: 'khgj',	type: 'string'},
				{name: 'create_at',	type: 'date', dateFormat: 'Y-m-d H:i:s'}
			]		 
		}),
		sortInfo:{field: 'id', direction: "ASC"}
});

var add_lxr = function() {
	var addkhxx_win = new Ext.Window({
		title: '增加客户',
		floating: true,
		shadow: true,
		draggable: true,
		closable: true,
		modal: true,
		width: 357,
		height: 260,
		layout: 'absolute',
		plain: true,
		items: [{
				xtype: 'form',
				id : 'addkhxx_form',
				width: 357,
				height: 237,
				padding: 10,
				layout: 'absolute',
				items: [
						{
								xtype: 'label',
								text: '客户',
								x: 50,
								y: 10,
								width: 30
						},
						{
								xtype: 'label',
								text: '电话',
								x: 50,
								y: 40,
								width: 30
						},
						{
								xtype: 'label',
								text: '身份证',
								x: 40,
								y: 70,
								width: 50
						},
						{
								xtype: 'label',
								text: '联系人',
								x: 40,
								y: 100,
								width: 50
						},
						{
								xtype: 'label',
								text: '客户地址',
								x: 30,
								y: 130,
								width: 50
						},
						{
								xtype: 'label',
								text: '国籍',
								x: 50,
								y: 160,
								width: 50
						},
						{
								xtype: 'textfield',
								fieldLabel: 'Label',
								x: 110,
								y: 10,
								width: 190,
								name: 'khxm'
						},
						{
								xtype: 'textfield',
								fieldLabel: 'Label',
								x: 110,
								y: 40,
								width: 190,
								name: 'khdh'
						},
						{
								xtype: 'textfield',
								fieldLabel: 'Label',
								x: 110,
								y: 70,
								width: 190,
								name: 'khsfz'
						},
						{
								xtype: 'textfield',
								fieldLabel: 'Label',
								x: 110,
								y: 100,
								width: 190,
								name: 'khlxr'
						},
						{
								xtype: 'textfield',
								fieldLabel: 'Label',
								x: 110,
								y: 130,
								width: 190,
								name: 'khdz'
						},
						{
								xtype: 'combo',
								x: 110,
								y: 160,
								width: 190,
								name: 'khgj',
								store: gj_store,
								emptyText:'',
								mode: 'local',
								valueField:'text',
								displayField:'text',
								triggerAction:'all'
						},
						{
								xtype: 'textfield',
								hidden : true,
								name : 'kh_id'
						}
				]
		}],
		buttons:[{
			text: '保存',
			handler: function(){
				var pars = Ext.getCmp("addkhxx_form").getForm().getValues();
				pars['yg_id']=currentUser.id;
				pars['yg_xm']=currentUser.login;
				new Ajax.Request("/desktop/add_khxx", 
					{ method: "POST",
						parameters: pars,
						onComplete:	 function(request) {
							addkhxx_win.close();

							//reload  search_lxr
							var search_str = Ext.getCmp('search_lxr_query').getValue();
							khxx_store.baseParams={filter:search_str};
							khxx_store.load();
							
						}
					});
			}
		},{
			text: '取消',
			handler: function(){
				addkhxx_win.close();
			}
		}]						
	});
	addkhxx_win.show();
};

var delete_lxr = function(gsm) {
	var select = gsm.getSelections()[0].data;
	
	var pars = "id=" + select.id;
	new Ajax.Request("/desktop/delete_khxx", { 
		method: "POST",
			parameters: pars,
			onComplete:	 function(request) {
        //this.ctxRow = null;
        gsm.grid.store.reload();
			}
	});
};

Ext.data.Store.prototype.applySort = function () {
	if (this.sortInfo && !this.remoteSort) {
		var s = this.sortInfo, f = s.field;
		var st = this.fields.get(f).sortType;
		var fn = function(r1, r2) {
			var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
			if (typeof(v1) == "string") {
				return v1.localeCompare(v2);
			}
			return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
		};
		this.data.sort(s.direction, fn);
		if (this.snapshot && this.snapshot != this.data) {
			this.snapshot.sort(s.direction, fn);
		}
	}
};

hs.graphicsDir = '/javascripts/mfbase/highslide/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.dimmingOpacity = 0.75;

// define the restraining box
hs.useBox = true;
hs.width = 640;
hs.height = 480;

// Add the controlbar
hs.addSlideshow({
	//slideshowGroup: 'group1',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: 1,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});

hs.lang = {
	cssDirection: 'ltr',
	loadingText: '载入中...',
	loadingTitle: '取消',
	focusTitle: '置于最前',
	fullExpandTitle: '原始尺寸',
	creditsText: '基于<i>Highslide JS</i>',
	creditsTitle: '查看 Highslide JS 官方首页',
	previousText: '上一张',
	nextText: '下一张',
	moveText: '移动',
	closeText: '关闭',
	closeTitle: '关闭 (退出键)',
	resizeTitle: '调整尺寸',
	playText: '播放',
	playTitle: '播放幻灯片 (空格键)',
	pauseText: '暂停',
	pauseTitle: '暂停幻灯片 (空格键)',
	previousTitle: '上一张 (左方向键)',
	nextTitle: '下一张 (右方向键)',
	moveTitle: '移动',
	fullExpandText: '完整尺寸',
	number: 'Image %1 of %2',
	restoreTitle: '单击关闭图片,单击不放拖动图片。使用方向键进行图片切换。'
};

var ky_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_kybh'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var fyxx_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_fybh'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var txStore = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
				url: '/desktop/get_dkgj'
		}),

		reader: new Ext.data.JsonReader({
			totalProperty: 'results', 
			root: 'rows',							
			fields: [
					 
			]		 
		}),
		sortInfo:{field: 'id', direction: "DESC"}
});

// create the Grid
var qzgjGrid = new Ext.grid.GridPanel({
		store: this.qzgjStore,
		columns: [
			 // {id:'id',header: 'id', width: 20, hidden: true, dataIndex: 'id', sortable: true},
			 {header: '跟进信息',		width: 250, sortable: true, dataIndex: 'message'},
			 {header: '部门',			width: 50, sortable: true,	dataIndex: 'ygbm'},
			 {header: '跟进人',		width: 50, sortable: true,	dataIndex: 'ygxm'},
			 {header: '最后更新日期', width: 100, sortable: true,	 renderer: Ext.util.Format.dateRenderer('Y-m-d'), dataIndex: 'create_at'}
		],
		stripeRows: true
		//autoExpandColumn: 'message',
		// config options for stateful behavior
		//stateful: true,
		//stateId: 'grid'				 
});

var xxly_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_xxly'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var xfdj_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_xfdj'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var cfms_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_cfms'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var gsgm_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_gsgm'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var syzlx_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_syzlx'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var zwbh_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_zwbh'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var khjb_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_khjb'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var khlb_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_khlb'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});

var users_store = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url:'/desktop/get_users'}),
	reader: new Ext.data.ArrayReader({},[
		{name:'id'}, 
		{name:'value'}
	])
});
